package base.Reflct;

import java.io.FileInputStream;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Properties;

public class 动态反射 {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
        // 创建Properties对象
        Properties port = new Properties();
        FileInputStream fis = new FileInputStream(".\\src\\base\\Reflct\\config.properties");
        port.load(fis);
        // 获取到config配置文件中的classname和method值
        String classname = port.getProperty("classname");
        String method = port.getProperty("method");

        Class clazz =  Class.forName(classname);//全类名
        Object obj = clazz.newInstance();//创建对象

        Method meth = clazz.getDeclaredMethod( method );//获取方法
        meth.setAccessible(true);//暴力反射,忽略访问权限修饰符
        meth.invoke(obj);
    }
}
